<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Players extends CI_Model {

    
    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }
    
        
    function getAllPlayer()
    {
        //$query = $this->db->get_where('ss_player', array('enabled' => 1));
        $query = $this->db->select('p.*,t.team_name')
     				->from('ss_player as p')
     				->where('p.enabled', 1)
     				->join('ss_team as t', 't.teamid = p.teamid', 'LEFT')
     				->get();
        
        return $query->result();
    }

    function get_player($playerid){
    	
    	//$query = $this->db->get_where('ss_player', array('playerid' => $playerid));
    	$query = $this->db->select('p.*,t.teamid')
     				->from('ss_player as p')
     				->where('p.playerid', $playerid)
     				->join('ss_team as t', 't.teamid = p.teamid', 'LEFT')
     				->get();
    	
    	return $query->result();
    	
    }

    function create_player($name,$no,$position,$height,$weight,$birth,$gender,$picture,$teamid,$enabled)
    {
    	$this->name = $name; // please read the below note
    	$this->no = $no;
    	$this->position = $position;    	
    	$this->height = $height;
    	$this->weight = $weight;
    	$this->birth = $birth;
    	$this->gender = $gender;
       	$this->picture = $picture;
       	$this->teamid = $teamid;       	
       	$this->enabled = $enabled;
    	$this->create_date = date("Y-m-d H:i:s");
    
    	$this->db->insert('ss_player', $this);
    }
    
    function edit_player($playerid,$name,$no,$position,$height,$weight,$birth,$gender,$picture,$teamid,$enabled)
    {
    	$this->name = $name; // please read the below note
    	$this->no = $no;
    	$this->position = $position;    	
    	$this->height = $height;
    	$this->weight = $weight;
    	$this->birth = $birth;
    	$this->gender = $gender;
       	$this->picture = $picture;
       	$this->teamid = $teamid;       	
       	$this->enabled = $enabled;
    	    
    	$this->db->update('ss_player', $this, array('playerid' => $playerid));
    }
    
    function delete_player($playerid){
    	$this->db->delete('ss_player', array('playerid' => $playerid));
    }
    
    /*function insert_entry()
    {
        $this->title   = $_POST['title']; // please read the below note
        $this->content = $_POST['content'];
        $this->date    = time();

        $this->db->insert('entries', $this);
    }

    function update_entry()
    {
        $this->title   = $_POST['title'];
        $this->content = $_POST['content'];
        $this->date    = time();

        $this->db->update('entries', $this, array('id' => $_POST['id']));
    }
*/
}